var PriceStrategy = function(){
	var strategy = {
		return30 : function(price){
			return + price + parseInt(price / 100) * 30;
		},
		return50 : function(price){
			return + price + parseInt(price / 100) * 50;
		},
		return90 : function(price){
			return price * 100 * 90 / 10000;
		},
		return80 : function(price){
			return price * 100 * 80 / 10000;
		},
		return50 : function(price){
			return price * 100 * 50 / 10000;
		}
	}
	return function(algorithm, price){
		return strategy[algorithm] && strategy[algorithm](price)
	}
}();

var price = PriceStrategy('return50', '314.67');
console.log(price);


var InputStrategy = function(){
	var strategy = {
		notNull : function(value){
			return /\s+/.test(value) ? '请输入内容' : '';
		},
		number : function(value){
			return /^[0-9]+(\.[0-9]+)?$/.test(value) ? '' : '请输入数字';
		},
		phone : function(value){
			return /^\d{3}\-\d{8}$|^|d{7}$/.test(value) ? '' : '请输入正确的电话号码格式，如：010-123456578 或 0418-1234567';
		}
	}
		return {
			check : function(type, value){
				value = value.replace(/^\s+|\s+$/g, '');
				return strategy[type] ? strategy[type](value) : '没有该类型的方法'
			},
			addStrategy : function(type, fn){
				strategy[type] = fn;
			}
		}
}();


InputStrategy.addStrategy('nickname', function(value){
	return /^[a-zA-Z]\w{3,7}$/.test(value) ? '' : '请输入4-8位昵称，如：YYOH';
});

function $tag(tag, context){
	context = context || document;
	return context.getElementsByTagName(tag);
}
$tag('input')[1].onclick = function(){
	var value = $tag('input')[0].value;
	$tag('span')[0].innerHTML = InputStrategy.check('nickname', value);
}


